package controller

import (
	"git.tmuyu.com.cn/ginOne/models"
	"git.tmuyu.com.cn/ginOne/service"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"io/ioutil"
	"log"
)

var GE gin.HandlerFunc = func(c *gin.Context) {
	for k, v := range c.Request.Header {
		logrus.Infof("key:", k, "values:", v)
	}
	signature, _ := c.GetQuery("signature") // 加密签名
	timestamp := c.Query("timestamp")       //时间戳
	nonce := c.Query("nonce")               //随机数
	echostr := c.Query("echostr")           //随机字符串
	var Wxurl models.WxUrl
	Wxurl.Signature = signature
	Wxurl.Timestamp = timestamp
	Wxurl.Nonce = nonce
	Wxurl.Echostr = echostr
	if !service.ValidateUrl(Wxurl) {
		log.Println("Wechat Service: this http request is not from Wechat platform!")
		return
	}
	log.Println("Wechat Service: validateUrl Ok!")
	c.AbortWithStatusJSON(200, gin.H{
		"echostr": Wxurl.Echostr,
	})
}
var ANY gin.HandlerFunc = func(c *gin.Context) {
	logrus.Warnf("#######################")
	for k, v := range c.Request.Header {
		logrus.Infof("key:", k, "values:", v)
	}
	logrus.Warnf("#######################")
	bod, _ := ioutil.ReadAll(c.Request.Body)
	logrus.Infof("body", string(bod))
	c.AbortWithStatusJSON(200, gin.H{
		"ok": "yes",
	})
	return
}

var POST gin.HandlerFunc = func(c *gin.Context) {

}

var DELETE gin.HandlerFunc = func(c *gin.Context) {

}
